<template>
	<view class="content">
		<navTop :title="navtop.title" :isHeight="false"  :color="navtop.color" :isBack="false"></navTop>
		<view class="content-top">
			<view class="bennaer-title">
				<!-- Banner Title -->
			</view>
			<view class="banner-tips" @click="showLang = true" >
				<picker @change="bindPickerChange" class="banner-tips__icon" :value="index" :range="array">
					
					<view class="post-box__banner">
						<view class="uni-input">
							<image :src="Ib" mode="" class="ib"></image>
						{{array[index]}}</view>
					</view>
				</picker>
			</view>
			<swiper class="swiper-box"
			@change="changeSwpier"
				indicator-dots="true" 
				autoplay="true" 
				interval="5000" 
				duration="1500"	>
				<swiper-item v-for="(item , index) in imageAll" :key="index" class="innert-box">
					<image :src="item.imgUrl" class="item-img" mode="widthFix"></image>
					<text class="banner-title">{{imageAll[index].title}}</text>
				</swiper-item>
				
			</swiper>
				<view class="banner-index">
					<view class="bannaer-index__item" :class="{active: bannerIndex == i}" v-for="(v, i) in imageAll">
						
					</view>
				</view>
		</view>
		
		<view class="content-body">
			<view class="content-new__title">
				<text>Video News</text>
				<text class="content-new__btn" @click="gotoVideo">
					See all
				</text>
			</view>
			<view class="content-body__list">
				<view class="content-body__item" v-for="(v, i) in videoList" :key="i" @click="gotoVideoDetail(v, i)">
					<view class="post-box">
						<image :src="v.imgUrl" mode="aspectFit" class="content-body__img"></image>
						<text class="post-time">{{v.timeLength || '00:00'}}</text>
					</view>
					<view class="content-body__text">
						{{v.title || ''}}
					</view>
				</view>
			</view>

			<view class="content-body__news">
				<view class="content-new__title">
					<text>Recent News</text>
					<text class="content-new__btn" @click="gotoRecent">
						See all
					</text>
				</view>
				<view class="content-new__item" v-for="(v, i) in newsList" :key="i" @click="gotoDetail(v, i)">
					<image :src="v.imgUrl"  class="content-item__img"  mode="aspectFill"></image>
					<view class="content-item__info">
						<view class="content-item__title">
							{{v.title || ''}}
						</view>
						<view class="content-item__tips">
							{{v.tips}}
						</view>
					</view>
				</view>
			</view>
			<!-- 登录弹窗 -->
			<view class="not-login__view" :style="{'top': isLogin ? '120vh': '0'}">
				<image :src="'/static/logo.jpg'" mode="" class="app-img"></image>
				<view class="app-name">龙华online</view>
				<view class="app-info">This is a slogan</view>
				<button class="login-btn" open-type="getUserInfo" withCredentials="true" lang="zh_CN" @getuserinfo="wxGetUserInfo" >
					授权微信登录
				</button>
			</view>
		</view>
		
		<customTarbar :selectIndex="0" />
	</view>
</template>
<script>
import navTop from '@/components/nav-title.vue'
import customTarbar from '@/components/custom-tarbar.vue';

import banner from '@/static/home_active.png'
import ds from '@/static/ds.png'
import vp from '@/static/vp.png'
import uc from '@/static/uc.png'
import gc from '@/static/gc.png'
import bgImg from '@/static/bg_img.png'
import logo from '@/static/logo.jpg'
import Ib from '@/static/i-b.png'
	export default {
		components: {
			navTop,
			customTarbar
		},
		data() {
			return {
				Ib,
				index: 0,
				logo,
				isLogin: true,
				userInfo: {},
				wxInfo: {},
				navtop: {
					title: ' ',
					color: '#024230'
				},
				imageAll: [
				],
				bannerIndex: 0,
				array: ['EN', 'ZH', '한국어', '日本語', 'Français', 'Русский язык'],
				Langlists: [
					{
						title: '中文',
						value: 'ZH'
					},
					{
						title: 'English',
						value: 'EN'
					},
					{
						title: '한국어',
						value: '한국어'
					},
					{
						title: '日本語',
						value: '日本語'
					},
					{
						title: 'Français',
						value: 'Français'
					},
					{
						title: 'Русский язык',
						value: 'Русский язык'
					}
				],
				videoList: [
					// {
					// 	imag: ds,
					// 	bgimg: bgImg,
					// 	text: 'Dynamic Square',
					// 	url: '/pages/square/index'
					// },
					// {
					// 	imag: vp,
					// 	bgimg: bgImg,
					// 	text: 'Visa Processing',
					// 	url: '/pages/visa/index'
					// },
					// {
					// 	imag: uc,
					// 	bgimg: bgImg,
					// 	text: 'User Center',
					// 	url: '/pages/me/index'
					// },
					// {
					// 	imag: gc,
					// 	bgimg: bgImg,
					// 	text: 'Group Chat'
					// }
				]
				,newsList: [
				]
			}
		},
		onLoad() {
		},
		onShow() {
			this.getVideo()
			this.getBanner()
			this.getList()
			this.isLogin = uni.getStorageSync("openId") || ''
			let lan = uni.getStorageSync("langSetting")
			if(lan == 'zh') {
				 this.$i18n.locale = 'zh-CN'
				 uni.setStorageSync('langSetting', 'zh')
				 this.index = 1
			}else{
                 this.$i18n.locale = 'en-US'
				 uni.setStorageSync('langSetting', 'en')
				 this.index = 0
			}
		},
		methods: {
			getVideo() {
				this.$http('get', '/app/video/list', {
					page: 1,
					limit: 4
				}).then(res => {
					if (res.success) {
						// res.data.forEach((v) => {
						// 	v.timeLength = this.$utils.getTime(v.timeLength)
						// })
						this.videoList = res.data
					}
				})
			},
			gotoDetail(v, i) {
				uni.navigateTo({
					url: `/pages/index/recentDetail?id=${v.id}`
				})
			},
			gotoVideoDetail(v, i) {
				uni.navigateTo({
					url: `/pages/index/videoDetail?id=${v.id}`
				})
			},
			gotoRecent() {
				uni.navigateTo({
					url: '/pages/index/recents'
				})
			},
			gotoVideo() {
				uni.navigateTo({
					url: "/pages/index/videos"
				})
			},
			bindPickerChange(v,i) {
				// 中文，English，한국어，日本語，Français，Русский язык
				this.index = v.detail.value
				if (v.detail.value == 1) {
					this.$i18n.locale = 'en-US'
				   uni.setStorageSync('langSetting', 'en')
				} else if (v.detail.value == 0){
					this.$i18n.locale = 'zh-CN'
				   uni.setStorageSync('langSetting', 'zh')
				} else if (v.detail.value == 2){
					this.$i18n.locale = 'Korean'
				   uni.setStorageSync('langSetting', 'Korean')
				} else if (v.detail.value == 3){
					this.$i18n.locale = 'Japanes'
				    uni.setStorageSync('langSetting', 'Japanese')
				} else if (v.detail.value == 4){
					this.$i18n.locale = 'French'
				    uni.setStorageSync('langSetting', 'French')
				} else if (v.detail.value == 5){
					this.$i18n.locale = 'Russian'
				    uni.setStorageSync('langSetting', 'Russian')
				}
			},
			getBanner() {
				this.$http('get', '/app/index/list').then(res => {
					if (res.success) {
						this.imageAll = res.data || []
					}
				})
			},
			getList() {
				this.$http('get', '/app/realtimeInfo/list', {
					page: 1,
					limit: 20
				}).then(res => {
					if (res.success) {
						res.data.forEach((v) => {
							v.tips = this.$utils.getTimerOff(v.createTime)
						})
						this.newsList = res.data
					}
				})
			},
			wxGetUserInfo() {
				let _this = this;
				uni.getUserInfo({
					provider: 'weixin',
					success: (infoRes) => {
						console.log(infoRes)
						this.wxInfo = infoRes.userInfo
						uni.setStorageSync('wxInfo', infoRes.userInfo)
						this.wxLoign()
					},
					fail(res) {}
				});
			},
			changeSwpier(e) {
			console.log(e)
			this.bannerIndex = e.detail.current
			},
			wxLoign() {
				uni.showLoading({
					title: '请稍候...'
				})
				uni.login({
				  provider: 'weixin',
				  success: (loginRes) =>  {
					uni.setStorageSync('code', loginRes.code)
					this.$http('post', '/app/getOpenId', {
						code: loginRes.code
					}, {
						'Content-Type': 'application/x-www-form-urlencoded'
					}).then((res) => {
						uni.hideLoading();
						if (res.success) {
							console.log(res)
							uni.setStorageSync('openId', res.data.openId)
							uni.setStorageSync('userInfo', res.data)
							this.isLogin = true
							this.userInfo = res.data
							if (!res.data.name ||res.data.name == 'null') {
								uni.navigateTo({
									url: '/pages/me/lang'
								});
								return false
							}
						}
					})
				  }
				});
			}
		}
	}
</script>

<style lang="less">
.content{
	background-color: #FBFCFE;
}
/* 轮播 */
.swiper-box{
	height: 600rpx;
	position: relative;
	
}

.banner-index {
	position: absolute;
	bottom: 146rpx;
	left: 30rpx;
	display: flex;
	.active {
		width: 40rpx;
		height: 6rpx;
		background: #FFFFFF;
		border-radius: 4rpx;
	}
}
.item-img {
	width: 100%;
	// height: inherit;
}
/deep/ .swiper-box .wx-swiper-dots.wx-swiper-dots-horizontal{
     margin-bottom: 2rpx;
}
/deep/ .swiper-box .wx-swiper-dot{
    width:16rpx;
    display: inline-flex;
    height: 6rpx;
    justify-content:space-between;
    background: rgba(255,255,255,0.45);
}
/deep/ .swiper-box .wx-swiper-dot::before{
    content: '';
    flex-grow: 1; 
    background: rgba(255,255,255,0.45);
    border-radius: 8rpx
}
/deep/ .swiper-box .wx-swiper-dot-active::before{
    content: '';
    width:40rpx !important;
    flex-grow: 1; 
    display: inline-flex;
    height: 6rpx;
    background:rgba(255,255,255,1); 
}
.content-top {
	position: relative;
}
.banner-tips {
	position: absolute;
	top: 200rpx;
	right: 0;
	min-width: 130rpx;
	height: 58rpx;
	line-height: 58rpx;
	background: linear-gradient(270deg, #439BFF 0%, #0078FF 100%);
	box-shadow: 0px 4px 16px 0px rgba(0, 120, 255, 0.25);
	border-radius: 15px 0px 0px 15px;
	color: #fff;
	z-index: 9999;
}
.banner-tips__icon {
	min-width: 24rpx;
	height: 24rpx;
	margin: 0 13rpx 0 22rpx;
}
.bennaer-title {
	position: absolute;
	left: 30rpx;
	top: 292rpx;
	font-size: 72rpx;
	font-family: Helvetica-Bold, Helvetica;
	font-weight: bold;
	color: #FFFFFF;
	z-index: 999;
}


.content-body{
	padding: 0 30rpx;
	margin-top: -40rpx;
	position: relative;
	z-index: 999;
}
.content-body__list {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;flex-wrap: wrap;
}
.content-body__item {
	width: 336rpx;
	height: 324rpx;
	// padding: 40rpx 40rpx 36rpx;
	box-sizing: border-box;
	position: relative;
	margin-bottom: 30rpx;
	border-radius: 4px;
	background-color: #fff;
	box-shadow: 0px 4px 12px 0px rgba(55, 58, 64, 0.08);
	
	.post-box {
		position: relative;
	}
	.post-time {
		position: absolute;
		bottom: 20rpx;
		left: 0;
		right: 0;
		height: 46rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		padding: 0 16rpx;
		// background: linear-gradient(180deg,rgba(0,0,0,0.00) 0%, rgba(0,0,0,0.15) 18%);
		color: #fff;
		font-size: 22rpx;
	}
}
.content-body__img {
	width: 336rpx;
	height: 192rpx;
	border-radius: 14rpx;
}

.content-body__text {
	display: block;
	width: 90%;
	font-size: 28rpx;
	margin: 24rpx auto;
	// padding: 24rpx;
	font-family: Helvetica;
	color: #1F1F1F;
	box-sizing: border-box;
	text-overflow: -o-ellipsis-lastline;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
}
.content-body__bg {
	width: 192rpx;
	height: 192rpx;
	position: absolute;
	right: 0;
	top: 0;
}
/deep/ .wx-swiper-dots{
	position: absolute;
	left: 60rpx !important;
	bottom: 80rpx !important;
}

/deep/ .uni-swiper-wrapper {
	position: relative;
}
/deep/ .uni-swiper-dots {
	position: absolute;
	left: 60rpx !important;
	bottom: 180rpx !important;
	z-index: 9999;
    display: inline-block;
    width: 14px !important;
    height: 4px !important;
    cursor: pointer;  
    -webkit-transition-property: background-color;  
    transition-property: background-color;  
    -webkit-transition-timing-function: ease;  
    transition-timing-function: ease;  
	/* background-color: #fff; */
    border-radius: 5px !important;
}

/deep/ .uni-swiper-dot {
	width: 16rpx;
	height: 8rpx;
	background: rgba(255, 255, 255, 0.45);
	border-radius: 4rpx;
}

/deep/ uni-swiper .uni-swiper-dot-active {  
    width: 40rpx !important;  
    background-color: #fff !important;  

}

.content-body__news {
	margin-top: 60rpx;
	padding-bottom: 160rpx;
}
.content-new__title {
	display: flex;
	justify-content: space-between;
	font-size: 40rpx;
	font-family: Helvetica-Bold, Helvetica;
	font-weight: bold;
	color: #1F1F1F;
	z-index: 99999;
	position: relative;
	margin-bottom: 24rpx;
}
.content-new__btn {
	font-size: 28rpx;
	font-family: Helvetica;
	color: #0078FF;
}
.content-new__item {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	background-color: #fff;
	margin-bottom: 30rpx;
}
.content-item__img {
	width: 260rpx;
	height: 182rpx;
	border-radius: 10rpx;
}
.content-item__info {
	padding: 36rpx 30rpx;
	width: 500rpx;
}
.content-item__title {
	font-size: 30rpx;
	font-family: Helvetica;
	color: #1F1F1F;
	margin-bottom: 18rpx;
	text-overflow: -o-ellipsis-lastline;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
}
.content-item__tips {
	font-size: 22rpx;
	font-family: Helvetica;
	color: rgba(31, 31, 31, 0.45);
	color: #1F1F1F;
}
.not-login__view {
	position: fixed;
	top: 120vh;
	height: 100vh;
	width: 100vw;
	left: 0;
	bottom: 140rpx;
	background-color: #fff;
	z-index: 999999;
	transition: all 0.3s;
	text-align: center;
	.app-img {
		width: 400rpx;
		height: 400rpx;
		margin: 15vh auto 0rpx;
	}
	.app-name {
		font-size: 48rpx;
		font-family: Helvetica-Bold, Helvetica;
		font-weight: bold;
		color: #1F1F1F;
		margin-bottom: 16rpx;
		text-align: center;
	}
	.app-info{
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(31, 31, 31, 0.65);
		text-align: center;
	}
	.login-btn {
		margin: 120rpx auto 0;
		width: 480rpx;
		height: 88rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #0078FF;
		border-radius: 28px;
		font-size: 32rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
	}
}
.ib {
	width: 32rpx;
	height: 32rpx;
	margin-right: 8rpx;
}
.post-box__banner {
	position: relative;
}
.innert-box {
	position: relative;
	.banner-title {
		position: absolute;
		bottom: 196rpx;
		left: 28rpx;
		font-size: 72rpx;
		font-family: Helvetica-Bold, Helvetica;
		font-weight: bold;
		color: #FFFFFF;
	}
}
.bannaer-index__item {
	width: 16rpx;
	height: 6rpx;
	background: rgba(255, 255, 255, 0.45);
	border-radius: 4rpx;
	margin-right: 12rpx;
}
</style>
